package com.jianggujin.redis.util;

import java.awt.Component;
import java.util.Locale;

import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class MessageUtils {
    static {
        JOptionPane.setDefaultLocale(Locale.US);
    }

    public static void showInfoMessage(Component parent, String title, String message) {
        JLabel messageLabel = new JLabel(message);
        SwingUtils.resizeFont(messageLabel);
        JOptionPane.showMessageDialog(parent, messageLabel, title, JOptionPane.INFORMATION_MESSAGE,
                ResourceUtils.ICON_LOGO);
    }

    public static void showInfoMessage(Component parent, String message) {
        showInfoMessage(parent, "Info", message);
        ;
    }

    public static void showErrorMessage(Component parent, String message) {
        JLabel messageLabel = new JLabel(message);
        SwingUtils.resizeFont(messageLabel);
        JOptionPane.showMessageDialog(parent, messageLabel, "Error", JOptionPane.ERROR_MESSAGE,
                ResourceUtils.ICON_LOGO);
    }

    public static void showWarningMessage(Component parent, String message) {
        JLabel messageLabel = new JLabel(message);
        SwingUtils.resizeFont(messageLabel);
        JOptionPane.showMessageDialog(parent, messageLabel, "Warning", JOptionPane.WARNING_MESSAGE,
                ResourceUtils.ICON_LOGO);
    }

    public static boolean showConfirm(Component parent, String message) {
        JLabel messageLabel = new JLabel(message);
        SwingUtils.resizeFont(messageLabel);
        return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(parent, messageLabel, "Confirm",
                JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, ResourceUtils.ICON_LOGO);
    }

    public static String showInput(Component parent, String title, String message, String initValue) {
        JLabel messageLabel = new JLabel(message);
        SwingUtils.resizeFont(messageLabel);
        return (String) JOptionPane.showInputDialog(parent, messageLabel, title, JOptionPane.INFORMATION_MESSAGE,
                ResourceUtils.ICON_LOGO, null, initValue);
    }
}
